{template header}
<style>
	 a{
		color:black;
	}

</style>

<script type="text/javascript" src="{SITE_URL}public/js/jquery.upload.v2.js"></script>

<div class="container">


<div class="row">


<div class="col-md-8">


    <div class="panel panel-default">
        <div class="panel-body">

			<ul class="nav nav-tabs" role="tablist">
				<li role="presentation"><a href="{tsUrl('duty','',null)}">记录</a></li>
				<li role="presentation" class="active"><a href="{tsUrl('duty','order',null)}">排班</a></li>
				<li role="presentation" ><a  href="{tsUrl('duty','sum',array('begintime'=>date('Y-m-d',strtotime('-1 month'))))}">统计</a></li>
				{if $type}
				<li style="float: right">
					<a onclick="addmemo()">设置提醒</a>
				</li>
				{else}
				{if $show_notice}
				<li style="float: right">
					<a data-toggle="modal" data-target="#notice">值班须知</a>
				</li>
				{/if}
				{/if}

				{if $GLOBALS['TS_USER']['userid'] == $group['userid'] || $GLOBALS['TS_USER']['isadmin']=='1'}
				<li style="float: right" {if $type}class="active"{/if}>
					<a href="{if !$type}{tsUrl('duty','order',array('groupid'=>$groupid,'next'=>$next,'type'=>1))}{else}{tsUrl('duty','order',array('groupid'=>$groupid,'next'=>$next))}{/if}"><i class="fa fa-cog"></i></a>
				</li>
				{/if}


			</ul>



 <div class="duty_index_list" style="padding-top:10px" >

	 <table style="width: 100%">
		 <tr>
			 <td style="width: 20%;text-align: left"><a href="{tsUrl('duty','order',array('groupid'=>$groupid,'next'=>$next-1,'type'=>$type))}"><i class="fa fa-hand-o-left"></i> 上周</a></td>
			 <td style="text-align: center;width:60%">
				 <ul class="nav">
					 <li class="dropdown" id="accountmenu">
						 <a  data-toggle="dropdown" href="#" style="font-size: 16px;font-weight: 600;color: black"> {$group['groupname']}排班表&nbsp;<img src="{SITE_URL}public/images/down.png" style="width:15px"></img></a>
						 <ul class="dropdown-menu">
							 {loop $arrGroup $key $item}
							 <li><a href="{tsUrl('duty','order',array('groupid'=>$item['groupid'],'next'=>$next))}">{$item['groupname']}</a></li>
							 {/loop}
						 </ul>
					 </li>
				 </ul>
			 </td>
			 <td style="width: 20%;text-align: right"><a href="{tsUrl('duty','order',array('groupid'=>$groupid,'next'=>$next+1,'type'=>$type))}">下周 <i class="fa fa-hand-o-right"></i></a></td>
		 </tr>

	 </table>
	 <div style="text-align: center; ">
		 <small style="border-bottom: 1px solid;">请点表头切换分馆，点<span style="font-weight: bold">日期</span>预约</small><br/>
		 <small style="padding-top: 10px;padding-bottom: 10px">图例：<span style="color: brown">棕色</span>-新人；<span style="font-weight: bold">粗体</span>-预约；<i class="fa fa-cutlery" style="color: #FF0000"></i> 订餐；<i class="fa fa-sticky-note-o" aria-hidden="true"></i> 备注，点开看</small>
	 </div>

	<table style="width:100% ">
		 {for $i=0;$i<=6;$i++ }

		 {php $thisday = strtotime('+'.$i.' day',$fromday)}
		 {php $dutyname=getDutyName($thisday,$groupid)}
	 <tr {if $thisday>=strtotime('today')&&!in_array($thisday,$strBan)&&(in_array($i,$strOpen)&&($group['begintime']&&$group['endtime'])&&$thisday>=$group['begintime']&&$thisday<=$group['endtime'])||in_array($thisday,$strAllow)}style="border-top:1px solid #CCCCCC;height: 60px;background-color:#83BF73"{else}style="border-top:1px solid #CCCCCC;height: 60px;background-color:orange"{/if}>
		 <td style="width:20%;padding: 5px 5px 5px 5px;text-align: center;border-right:1px solid #CCCCCC;"
			 {if $thisday>=strtotime('today')&&!in_array($thisday,$strBan)&&(in_array($i,$strOpen)&&($group['begintime']&&$group['endtime'])&&$thisday>=$group['begintime']&&$thisday<=$group['endtime'])||in_array($thisday,$strAllow)} onclick="openbox({$i},$arrUser['isrenzheng'])"{else}onclick="warning()"{/if}
				 >

			 <div style="font-size: 10px;color: blue">{php echo date('ymd',$thisday)}</div><div style="font-size: 10px;color: blue">周{php echo cnWeek($thisday)}</div>
		 </td>
		 <td>
			 <div >
				 <ul style="display: flex;flex-wrap: wrap;">
				 {loop $dutyname  $key $item}

					 {php $pureDuty=aac('duty')->find('duty',array('userid'=>$item['userid'],'cateid'=>1,'status'=>1));}
					 <li style="text-align: left;padding: 5px"><div style="font-size: 10px">
						 <a href="{tsUrl('user','duty',array('id'=>$item[user][userid]))}"><img class="img-circle" title="{$item[user][username]}" alt="{$item[user][username]}" src="{$item[user][face]}" width="12" /></a>

						 <a href="{tsUrl('duty','show',array('dutyid'=>$item[dutyid]))}"><span style="{if $item[status]==-1}font-weight:bold;{/if}color:{if !$pureDuty}brown{else}black{/if}"> {$item[user][username]}</span></a>
						 {if $item[lunch]}  <i class="fa fa-cutlery" style="color: #FF0000"></i>
						 {/if}
						 {if $item[memo]}
						 <a href="#"  id="tips1"  rel="popover" data-placement="auto left" data-content="{$item[memo]}" ><i class="fa fa-sticky-note-o" aria-hidden="true"></i> </a>
						 {/if}
						 </div>
						 {if $item['endtime']}
						 <div style="font-size: 5px">
							 {php echo date('H:i',$item['begintime'])}至{php echo date('H:i',$item['endtime'])}
						 </div>
						 {/if}
						 {if $GLOBALS[TS_USER][userid]==$item['userid']&&$item['status']<1}
						 <div style="font-size: 5px">	<a  href="javascript:void('0');" onclick="delDuty('{$item['dutyid']}')">删除</a></div>
						 {/if}
					 </li>
			 	 {/loop}
				 </ul>
				 {if $GLOBALS['TS_USER']['userid'] == $group['userid'] || $GLOBALS['TS_USER']['isadmin']=='1'}
				 	<span  style="float: right;{if !$type}display: none;{/if}padding-right: 10px" >
						 {if $thisday>=strtotime('today')}
							{if (in_array($i,$strOpen)||in_array($thisday,$strAllow))&&($group['begintime']&&$group['endtime'])&&$thisday>=$group['begintime']&&$thisday<=$group['endtime']}
							  {if in_array($thisday,$strBan)}
								  <input class="form_control" type="checkbox" onclick="allow({$thisday},{$groupid})"/>
							 {else}
								 <input class="form_control" type="checkbox" checked onclick="forbid({$thisday},{$groupid})" />
							 {/if}
						  {else}
							  {if !in_array($thisday,$strAllow)}
								  <input class="form_control" type="checkbox" onclick="allow1({$thisday},{$groupid})"/>
							 {else}
								 <input class="form_control" type="checkbox" checked onclick="forbid1({$thisday},{$groupid})" />
							 {/if}
						 {/if}
						{/if}
				 </span>
				{/if}
			 </div>

		 </td>
	 </tr>
		 {/for}
	</table>
            </div>

<div class="clear"></div>
<div class="page">{$pageUrl}</div>
<div>

</div>

</div>
</div>


</div>


<div class="col-md-4">
    <!--广告位-->
    {php doAction('gobad','300')}



</div>


</div>
</div>

<div id="do_duty_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h5 class="modal-title">预约排班</h5>
			</div>
			<div class="modal-body" >
				<form  id="comm-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=user&ac=do&ts=order">
					<div class="form-group">
						<label class="col-sm-3 control-label">服务处所：</label>
						<div class="col-sm-9">
							{$group['groupname']}
						</div>
						<input type="hidden" id='gid' name="groupid" value="{$groupid}">
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">服务日期</label>
						<div class="col-sm-3"><select  name="year" id="year" class="form-control"></select></div>
						<div class="col-sm-3"><select  name="month" id="month" class="form-control"></select></div>
						<div class="col-sm-3"><select  name="day"  id="day" class="form-control"></select></div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">值班起始时间</label>
						<div class="col-sm-3">
							<select  name="beginhour" id="beginhour" class="form-control">
								<option></option>
								{for $i=7;$i<19;$i++ }
								<option value="{$i}">{$i}</option>
								{/for}
							</select>
						</div>
						<div class="col-sm-3">
							<select  name="beginmin" id="beginmin" class="form-control">
								<option></option>
								{for $i=0;$i<=60;$i++ }
								<option value="{if $i<10}0{/if}{$i}">{if $i<10}0{/if}{$i}</option>
								{/for}
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">值班结束时间</label>

						<div class="col-sm-3">
							<select  name="endhour" id=endhour" class="form-control">
								<option></option>
								{for $i=7;$i<=19;$i++ }
								<option value="{$i}">{$i}</option>
								{/for}
							</select>
						</div>
						<div class="col-sm-3">
							<select  name="endmin" id="endmin" class="form-control">
								<option></option>
								{for $i=0;$i<=60;$i++ }
								<option value="{if $i<10}0{/if}{$i}">{if $i<10}0{/if}{$i}</option>
								{/for}
							</select>
						</div>
					</div>



					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">

							<button type="submit" class="btn btn-success">点击提交</button>
						</div>
					</div>
				</form>

			</div>
		</div>
	</div>
</div>
<!--{for $k=0;$k<=6;$k++ }-->
<div id="do_duty_form{$k}" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h5 class="modal-title">预约排班</h5>

					<div>预约前请在{$group[groupname]}工作群内向馆长确认一下预约日期是否开馆，以免误约；</div>
					<div>值班起止时间可以根据自己的具体条件修改；</div>
					<div>预约成功后，请截图发到工作群，并写一句鼓动语比如“我已预约值班，有人跟我搭档吗？”</div>

			</div>

			<div class="modal-body" >
				<div>

				</div>

				<form  id="comm-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=user&ac=do&ts=order">
					<div class="form-group">
						<label class="col-sm-3 control-label">服务处所：</label>
						<div class="col-sm-6 control-label">{$group['groupname']}</div>
						<input type="hidden" id='gid' name="groupid" value="{$groupid}">
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">服务日期：</label>
						<div class="col-sm-6 control-label">{php echo date('Y-m-d',strtotime('+'.$k.' day',$fromday))}</div>
						<input type="hidden" id='dutydate' name="dutydate" value="{php echo date('Y-m-d',strtotime('+'.$k.' day',$fromday))}">
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">值班起始时间</label>
						<div class="col-sm-3">
							<select  name="beginhour" id="beginhour" class="form-control">
								<option></option>
								{for $i=7;$i<=19;$i++ }
								<option value="{$i}" {if $i==11}selected{/if}>{$i}</option>
								{/for}
							</select>
						</div>
						<div class="col-sm-3">
							<select  name="beginmin" id="beginmin" class="form-control">
								<option></option>
								{for $i=0;$i<=60;$i++ }
								<option value="{if $i<10}0{/if}{$i}" {if $i==0}selected{/if}>{if $i<10}0{/if}{$i}</option>
								{/for}
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">值班结束时间</label>

						<div class="col-sm-3">
							<select  name="endhour" id=endhour" class="form-control">
								<option></option>
								{for $i=7;$i<=19;$i++ }
								<option value="{$i}" {if $i==15}selected{/if}>{$i}</option>
								{/for}
							</select>
						</div>
						<div class="col-sm-3">
							<select  name="endmin" id="endmin" class="form-control">
								<option></option>
								{for $i=0;$i<=60;$i++ }
								<option value="{if $i<10}0{/if}{$i}" {if $i==0}selected{/if}>{if $i<10}0{/if}{$i}</option>
								{/for}
							</select>
						</div>
					</div>

					{if $group['lunch']}

					<div class="form-group">
						<label class="col-sm-3 control-label">订餐：</label>
						<div class="col-sm-6 control-label"> <input name="lunch" type="checkbox" value="1" /></div>
					</div>

					{/if}

					<div class="form-group">
						<label class="col-sm-3 control-label">备注：</label>
						<div class="col-sm-6 control-label"><input name="memo" type="text" class="form-control"></div>

					</div>

					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">

							<button type="submit" class="btn btn-success">点击提交</button>
						</div>
					</div>
				</form>

			</div>
		</div>
	</div>
</div>
<!--{/for}-->
<div id="do_date_form" style="display:none;">

	<form  id="date-form" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=duty&ac=excel">

		<div class="form-group">
			<label class="col-sm-2 control-label">起始日期</label>
			<div class="col-sm-3"><select  name="year" id="year" class="form-control"></select></div>
			<div class="col-sm-3"><select  name="month" id="month" class="form-control"></select></div>
			<div class="col-sm-3"><select  name="day"  id="day" class="form-control"></select></div>
		</div>


		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">

				<button type="submit" class="btn btn-success">点击提交</button>
			</div>
		</div>
	</form>

</div>

<div id="setmemo" class="modal fade">
	<div class="modal-dialog" >
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h5 class="modal-title">设置预约提醒文字，馆员预约时可以看见</h5>
			</div>
			<form id="addform" class="form-horizontal">
				<div class="panel-body">
					<div class="form-group">
						<div class="col-md-12">
							<div id="tseditor"></div>
							<div style="display: none">
							<textarea class="form-control" id="memo" name="content" rows="6"  placeholder='说点儿什么呗'>{$group[memo]}</textarea>
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="col-md-12">
							<input type="hidden" name="groupid" id="groupid" value="{$groupid}">
							<button type="submit" class="btn btn-primary">提交</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

{if !$groupid}
<script>
	bootbox.alert('请点击标题右侧的向下箭头，选择所在馆；点击标题两侧的小手，向前或向后切换日期；点击左列的日期预约值班');
</script>
{/if}

<script>



	//提示不可预约
	function warning(){
		bootbox.alert('抱歉，橙色时段不可预约！');
	}

	//打开预约表单
	function openbox(i,isrenzheng){

		if(isrenzheng==1){
			$('#do_duty_form'+i).modal('show');
		}else{
			tsNotice('你还没有取得馆员资格！如果已经通过了考试，请点击<a href="{tsUrl('user','apply')}">这里</a>申报馆员资格；如果还没有参加培训和考试，请点击<a href="https://shimo.im/docs/fatOK9bmivgLQwuL">这里</a>查看了解详情。参加培训，通过考试取得馆员资格后，才能预约值班。');
		}

	}

	//统计截止时间表单
	function doDateForm(userid){

		if(userid==0){
			tsNotice('请登录后再操作！');
		}else{

			var content = $("#do_date_form").html();
			tsNotice(content);
		}
	}



	//删除服务记录
	function delDuty(dutyid){


		if (confirm('删除这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=del",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});

		}
	}
	//确认服务记录
	function verify(dutyid){


		if (confirm('确认这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=verify",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});

		}
	}

	//取消确认
	function cancel(dutyid){

		if (confirm('取消确认这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=cancel",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}

	//禁止排班
	function forbid(date,groupid){

		if (confirm('所选日期禁止排班吗')) {
			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=duty&ac=forbid",
				data: "date="+date+"&groupid="+groupid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}

	//允许排班
	function allow(date,groupid){


		if (confirm('所选日期允许排班吗')) {
			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=duty&ac=allow",
				data: "date="+date+"&groupid="+groupid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}
	//禁止排班
	function forbid1(date,groupid){

		if (confirm('所选日期禁止排班吗')) {
			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=duty&ac=forbid1",
				data: "date="+date+"&groupid="+groupid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}

	//允许排班
	function allow1(date,groupid){


		if (confirm('所选日期允许排班吗')) {
			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=duty&ac=allow1",
				data: "date="+date+"&groupid="+groupid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}

	$(function(){

		$('#do_duty_form').on('submit', function(e) {
			var year  = $('#year').val();
			var month  = $('#month').val();
			var day  = $('#day').val();
			var beginhour  = $('#beginhour').val();
			var beginmin  = $('#beginmin').val();
			var endhour  = $('#endhour').val();
			var endmin  = $('#endmin').val();
			var groupid  = $('#gid').val();

			if(beginhour==''||beginmin==''||endhour==''||endmin==''){
				bootbox.alert('请选择完整的时间！');
				return false;
			}

			$.ajax({
				url: "{SITE_URL}index.php?app=user&ac=do&ts=order",
				type: 'post',
				dataType: 'json',
				data: { year:year,month:month,day:day,beginhour:beginhour,beginmin:beginmin,endhour:endhour,endmin:endmin,groupid:groupid },
				success: function(data) {
					if(data.status == '1'){
						$('#do_duty_form').modal('hide');
						location.reload();
					}
				}
			});

		});

	});


	$(document).ready(function(e) {
		var date = new Date();
		var vYear = date.getFullYear();
		var vMon = date.getMonth() + 1;
		var vDay = date.getDate();
		var year;
		var month;
		var day;
		var str_year;
		var str_month;
		var t_month;
		var str_day;


				var first_year = date.getFullYear()-1;
//起始
				var last_year = date.getFullYear();
//终止年
				var t_year
				var i;
				var r;
				var y_v;
				var m_v;
				var d_v;
//写出年的选项
				for (i = last_year; i >= first_year; i--) {
					if (i != vYear) {
						$("[name=year]").append('<option value="' + i + '">' + i + '</option>');
					} else {
						$("[name=year]").append('<option value="' + i + '" selected>' + i + '</option>');
					}
				}
//写出月的选项
				for (i = 1; i <= 12; i++) {
					r = i ;
					if (i != vMon) {
						$("[name=month]").append('<option value="' + i + '">' + r + '</option>');
					} else {
						$("[name=month]").append('<option value="' + i + '" selected>' + r + '</option>');
					}
				}

//初始化日的值
				day();
//在年月的值发生变化时计算日期的天数
				$("[name=year]").change(function(){   day();   });
				$("[name=month]").change(function(){ day();
				});
//根据日期的天数，输出日选项

				function day(){
					var y_v=$("[name=year]").val();
					var m_v=$("[name=month]").val()-1;
					var d_v;
					var i;
					if((y_v%100!=0&&y_v%4==0)||y_v%400==0) {
						d_v=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
					}    else   {
						d_v=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
					}
					$("[name=day]").html("");
					for(i=1;i<=d_v[m_v];i++)   {
						if(i!=vDay)  {
							$("[name=day]").append('<option value="'+i+'">'+i+'</option>');
						}  else {
							$("[name=day]").append('<option value="'+i+'" selected>'+i+'</option>');
						}
					}
				}
			});

	//设置提醒
	function addmemo(){
		$('#setmemo').modal('show');
	}

	$(function(){
		$('#addform').on('submit', function(e) {
			var groupid = $('#groupid').val();
			var content = $('#memo').val();

			$.ajax({
				url: "{SITE_URL}index.php?app=group&ac=do&ts=setmemo",
				type: 'POST',
				dataType: 'json',
				data: {groupid:groupid,content:content},
				success :function(result) {
					window.location.reload();
				}
			});

		});
	});


</script>



{php doAction('tseditor','m')}

{template footer}